import Vue from "vue";
import VueRouter from "vue-router";
import Tabber from "@/views/Tabber.vue";
import My from "@/views/My";
import Home from "@/views/Home";
import Publish from "@/views/Publish";
import ArticlePage from "@/views/ArticlePage";
import login from "@/views/login";
import globel from "@/utils/global";
Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    redirect: "/Tabber",
  },
  {
    path: "/Home",
    redirect: "/Tabber",
  },
  {
    path: "/My",
    redirect: "/Tabber",
  },
  {
    path: "/Tabber",
    component: Tabber,
    redirect: "/Tabber/Home",
    children: [
      {
        path: "Home",
        component: Home,
      },
      {
        path: "My",
        component: My,
      },
    ],
  },
  {
    path: "/Publish",
    name: "Publish",
    component: Publish,
    beforeEnter: (to, from, next) => {
      if (globel.islogin) {
        next();
      } else {
        console.log(globel);
        console.log("没有登录");
      }
    },
  },
  {
    path: "/ArticlePage",
    name: "ArticlePage",
    component: ArticlePage,
  },
  {
    path: "/login",
    name: "login",
    component: login,
  },
];

const router = new VueRouter({
  routes,
});

export default router;
